package cn.com.cmbc.example;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.NamespaceDescriptor;
import org.apache.hadoop.hbase.client.Admin;
import org.apache.hadoop.hbase.client.Connection;
import org.apache.hadoop.hbase.client.ConnectionFactory;

import java.io.IOException;

public class HBaseNamespaceExample {
    public static void main(String[] args) {
        // 配置 HBase 连接
        Configuration configuration = new Configuration();
        configuration.set("hbase.zookeeper.quorum", "centos103"); // Zookeeper 地址
        configuration.set("hbase.zookeeper.property.clientPort", "2181"); // Zookeeper 端口

        try (Connection connection = ConnectionFactory.createConnection(configuration);
             Admin admin = connection.getAdmin()) {

            // 获取所有的 Namespace 描述
            NamespaceDescriptor[] namespaceDescriptors = admin.listNamespaceDescriptors();

            // 打印 Namespace 名称
            System.out.println("HBase Namespaces:");
            for (NamespaceDescriptor namespaceDescriptor : namespaceDescriptors) {
                System.out.println(namespaceDescriptor.getName());
            }

        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
